#!/bin/sh
#
# /etc/init.d/syslog-ng
#

PREFIX="syslog-ng: "
THISFILE=$0
syslogng="/sbin/syslog-ng"
PIDFILE="/var/run/syslog-ng.pid"
		
usage() {
	echo "${PREFIX}usage: $THISFILE [start|stop]"
}

case $1 in 

	start)
		echo "${PREFIX} starting"
		if [ -e "$PIDFILE" ]; then 
			echo "${PREFIX} warning: another syslog-ng seems to be running, trying to kill it"
			kill -9 `cat $PIDFILE`
			rm -f $PIDFILE
		fi
		$syslogng
		if [ "$?" != "0" ]; then 
			echo "${PREFIX} error, could not start daemon"
			rm -f $PIDFILE
		else 
			echo "${PREFIX} done"
		fi
		;;

	stop)
		echo "${PREFIX} stopping"
		kill `cat $PIDFILE`
		rm -f $PIDFILE
		echo "${PREFIX} done"
		;;

	*)

		usage
		exit 1
		;;

esac

